﻿using Aker.DevTeam;
using DevExpress.XtraReports.UI;
using System;
using System.Data;

namespace Aker.Cikislar
{
    public partial class CekiReport : XtraReport
    {
        string detailTableName;

        private DataTable dtMaster;
        private DataTable dtDetail;
        private DataSet ds;

        public CekiReport(int CikisId)
        {
            InitializeComponent();

            ds = Data.DM.ExecuteDataSet("GetCeki", CikisId);
            dtMaster = ds.Tables[0];
            dtDetail = ds.Tables[1];

            dtDetail.Columns.Add("#", typeof(int));
            for (int i = 0; i < dtDetail.Rows.Count; i++)
                dtDetail.Rows[i]["#"] = i + 1;

            detailTableName = dtDetail.TableName;
            DataRow dr = dtMaster.Rows[0];

            tcSevkiyatNo.Text = dr["CikisId"].ToString();
            tcSipNo.Text = dr["POrderId"].ToString();
            tcTeslimatAdresi.Text = dr["Address"].ToString();
            tcCikisTarihi.Text = ((DateTime)dr["CikilacakTarih"]).ToString("dd.MM.yyyy");
            tcAciklama.Text = dr["Aciklama"].ToString();
        }


        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            this.DataSource = ds;
            this.DataMember = detailTableName;

            BindCell(detailSiraNo, "#");
            BindCell(detailHammadde, "Hammadde");
            BindCell(detailBarkod, "IplikId");
            BindCell(detailKG, "CikilanKG", "{0:n}");
            //BindCell(detailTip, "Hammadde Tipi");
            //BindCell(detailRenk, "Renk");
            //BindCell(detailRenkKodu, "Renk Kodu");
            //BindCell(detailTedarikci, "Tedarikçi");
            //BindCell(detailBoyahane, "Adet", "{0:n}");
            //BindCell(detailLot, "Lot");
        }

        private void BindCell(XRTableCell cell, string columnName, string format = "")
        {
            if (format == "")
                cell.DataBindings.Add("Text", null, detailTableName + "." + columnName);
            else
                cell.DataBindings.Add("Text", null, detailTableName + "." + columnName, format);
        }

        private void OrderReport_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            //if (WithPictures)
            //    imgArticle.DataBindings.Add("Image", null, detailTableName + "." + "PhotoEmail");
            //else
            //{
            //    trDetail.Cells.Remove(detailPhoto);

            //    for (int i = 0; i < tblHeader.Rows[0].Cells.Count; i++)
            //    {
            //        tblDetail.Rows[0].Cells[i].WidthF = tblHeader.Rows[0].Cells[i].WidthF;
            //    }

            //    trDetail.HeightF = 10;
            //    Detail.HeightF = 10;
            //}
        }
    }
}